<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let arr = [18, 17, 5, 10, 9, 15, 10, 12, 11, 18]
        let direction1 = true
        let direction2 = false
        let res = []
        for (let i = 0; i < arr.length; i++) {
            let maxLength = 1
            for (let j = i + 1; j < arr.length; j++) {
                if (arr[j] > arr[j - 1] && direction1) {
                    maxLength++
                    direction1 = false
                } else if (arr[j] < arr[j - 1] && !direction1) {
                    maxLength++
                    direction1 = true
                }
            }

            let maxLength2 = 1
            for (let j = i + 1; j < arr.length; j++) {
                if (arr[j] < arr[j - 1] && !direction2) {
                    maxLength2++
                    direction2 = true
                } else if (arr[j] > arr[j - 1] && direction2) {
                    maxLength2++
                    direction2 = false
                }
            }

            res.push(Math.max(maxLength, maxLength2))
        }
        console.log(Math.max(...res))
    </script>
</body>

</html>